package chapter19.HandlerStream.Exercise;

import org.junit.Test;

import java.io.*;

/**
 * @Auther: Tx
 * @Date: 2022/7/23 23:03
 */
//处理流的综合使用，文件拷贝
public class FileCopy {
    @Test
    void test01(){
        String filePath = "e://hello.txt";
        String objPath = "e://helloCopy.txt";
        BufferedWriter bufferedWriter = null;
        BufferedReader bufferedReader = null;
        String readLine ;
//        读取文件
        try {
            bufferedReader = new BufferedReader(new FileReader(filePath));
            bufferedWriter = new BufferedWriter(new FileWriter(objPath));
            while ((readLine = bufferedReader.readLine())!=null){
                bufferedWriter.write(readLine);
                bufferedWriter.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                bufferedReader.close();
                bufferedWriter.close();
                System.out.println("拷贝完成");
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
